exports.install = function (Vue, options) {
  //Api Url
  Vue.prototype.api = "http://new.ujnxgzx.com/";
  //  拼接apiUrl
  Vue.prototype.apiUrl = function (value) {
    let _this = this;
    return _this.api + value;
  };

  // 生成随机字符串
  Vue.prototype.randomWord = function (randomFlag, min, max){
    let str = "",
      range = min,
      arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
    // 随机产生
    if(randomFlag){
      range = Math.round(Math.random() * (max-min)) + min;
    }
    for(let i=0; i<range; i++){
      let pos = Math.round(Math.random() * (arr.length-1));
      str += arr[pos];
    }
    return str;
  };

  //设置cookie
  Vue.prototype.setCookie = function (cname, cvalue, exdays) {
    let d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    let expires = "expires=" + d.toUTCString();
    // console.info(cname + "=" + cvalue + "; " + expires);
    document.cookie = cname + "=" + cvalue + "; " + expires;
    // console.info(document.cookie);
  };
  //获取cookie
  Vue.prototype.getCookie = function (cname) {
    let name = cname + "=";
    let ca = document.cookie.split(';');
    for (let i = 0; i < ca.length; i++) {
      let c = ca[i];
      while (c.charAt(0) === ' ') c = c.substring(1);
      if (c.indexOf(name) !== -1) return c.substring(name.length, c.length);
    }
    return "";
  };
  //清除cookie
  Vue.prototype.clearCookie = function () {
    this.setCookie("token", "", -1);
  };
  //验证cookie
  Vue.prototype.checkCookie = function (token = "", expire_time = "") {
    let $token = this.getCookie("token");
    if ($token !== "") {
      // console.log("token " + token);
    } else {
      if (token !== "" && token != null && expire_time !== "" && expire_time !== null) {
        this.setCookie("token", token, 10);
        this.setCookie("expire_time", expire_time, 10);
      }
    }
  };
};
